package com.why.simpleboot.core.server.netty.resolver;

import com.why.simpleboot.core.annotation.mvc.PathVariable;
import com.why.simpleboot.core.annotation.mvc.RequestBody;
import com.why.simpleboot.core.annotation.mvc.RequestParam;
import com.why.simpleboot.core.server.netty.resolver.impl.PathVariableParameterResolver;
import com.why.simpleboot.core.server.netty.resolver.impl.ReqeustBodyParameterResolver;

import com.why.simpleboot.core.server.netty.resolver.impl.RequestParamParameterResolver;

import java.lang.reflect.Parameter;

/**
 * @program: why-simpleboot-framework
 * @description:
 * @author: @why
 * @create: 2021-05-23 17:27
 **/
public class ParameterResolverFactory {
    private static final ParameterResolver PATH_VARIABLE_RESOLVER = new PathVariableParameterResolver();
    private static final ParameterResolver REQUEST_BODY_RESOLVER = new ReqeustBodyParameterResolver();
    private static final ParameterResolver REQUEST_PARAM_RESOLVER = new RequestParamParameterResolver();


    public static ParameterResolver getResolver(Parameter parameter) {
        if (parameter.isAnnotationPresent(PathVariable.class)) {
            return PATH_VARIABLE_RESOLVER;
        } else if (parameter.isAnnotationPresent(RequestBody.class)) {
            return REQUEST_BODY_RESOLVER;
        } else if (parameter.isAnnotationPresent(RequestParam.class)) {
            return REQUEST_PARAM_RESOLVER;
        } else {
            // TODO: 2021/5/23 后期可以加入一个通用解析器，完成参数解析 解析失败就抛异常
            throw new NullPointerException("没有指定解析器。。。");
        }

    }

}
